package com.hainatong.shiphelper.utils;


import com.blankj.utilcode.util.StringUtils;
import com.hainatong.shiphelper.module.warehouse.entity.ChuKuRaramBean;
import com.hainatong.shiphelper.module.warehouse.entity.ChukuGoodsParam;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

/**
 *  处理 各种 数据的 静态 方法
 */
public class ComDataUtils
{

    public static ChuKuRaramBean[] getChukuParamsByLinYongInfo(List<ChukuGoodsParam> goodsParamsList, String worker, String workerId, String remark
            , String chargeUser , String chargeUserId , String shipName)
    {
        ChuKuRaramBean[] chuKuBeans = new ChuKuRaramBean[ goodsParamsList.size() ];

        for( int i=0 ; i < goodsParamsList.size() ;i++ )
        {
            ChuKuRaramBean chuKuGoods = ChuKuRaramBean.getChuKuParamsByGoodsInfo( goodsParamsList.get(i) );
            chuKuGoods.setEmployer( worker );
            chuKuGoods.setEmployer_id( workerId );
            if(!StringUtils.isEmpty( remark ))
            {
                chuKuGoods.setRemark( remark );
            }
            chuKuGoods.setCharge_user(chargeUser);
            chuKuGoods.setCharge_user_id( chargeUserId );

            chuKuGoods.setShip_name(shipName );
            chuKuBeans[i] = chuKuGoods;
        }

        return chuKuBeans;
    }


    /**
     *  休假管理 获取 休假的 小时 数量
     * @param startTime
     * @param endTime
     * @return
     */
    public static int getHolidayHoursCount(String startTime ,String endTime)
    {
        int count = 0;
        SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
        try
        {
            Date startTimeD = formatDate.parse( startTime );
            Date endTimeD = formatDate.parse( endTime );
            long holidayTime =  endTimeD.getTime() - startTimeD.getTime();
            //LogUtils.e("holidayTime = " + holidayTime  );
            count = (int)(holidayTime/(1000*60*60));
        }
        catch (ParseException e)
        {
            e.printStackTrace();
        }
        return count;
    }

    /**
     *  结束时间 是否 正确
     * @param startTime
     * @param endTime
     * @return
     */
    public static boolean isEndTimeRight(String startTime ,String endTime)
    {
        boolean isReight = false;
        SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
        try
        {

            Date startTimeD = formatDate.parse( startTime );
            Date endTimeD = formatDate.parse( startTime );
            //结束 时间戳  大于 开始 时间戳
            if( endTimeD.getTime() >= startTimeD.getTime() )
            {
                isReight = true;
            }
        }
        catch (ParseException e)
        {
            e.printStackTrace();
        }
        return isReight;
    }

}
